package com.java.springcloud.controller;

import com.java.springcloud.service.RocketMqService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author dushougudu
 */
@RestController
@Slf4j
@RequestMapping("/rocketmq")
public class RocketMqController {
    @Autowired
    private RocketMqService rocketMqService;

    @PostMapping("/send")
    public String send(String msg, String topic) {
        rocketMqService.send(msg, topic);
        return "success";
    }

    @PostMapping("/syncSendOrderly")
    public String syncSendOrderly(String msg, String topic, String hashkey) {
        rocketMqService.syncSendOrderly(msg, topic, hashkey);
        return "success";
    }

    @PostMapping("/batchSyncSendOrderly")
    public String batchSyncSendOrderly(String msg, String topic, String hashkey) {
        for (int i = 0; i < 10; i++) {
            rocketMqService.syncSendOrderly(msg + i, topic, hashkey);
        }
        return "success";
    }

    @PostMapping("asyncSend")
    public String asyncSend(String msg, String topic) {
        rocketMqService.asyncSend(msg, topic);
        return "success";
    }

    @PostMapping("sendIntransaction")
    public String sendIntransaction(String msg, String topic) {
        rocketMqService.sendIntransaction(msg, topic);
        return "success";
    }

    @PostMapping("sendDelay")
    public String sendDelay(String msg, String topic) {
        rocketMqService.sendDelay(msg, topic);
        return "success";
    }


}
